class Member:
    def __init__(self, level):
        self.level = level

    @property
    def discount_rate(self):
        if self.level == 'VIP':
            return 0.8  # VIP会员享受8折优惠
        elif self.level == 'Gold':
            return 0.9  # 金卡会员享受9折优惠
        elif self.level == 'Silver':
            return 0.95  # 银卡会员享受95折优惠
        else:
            return 1.0  # 非会员无折扣

class Product:
    def __init__(self, name, price):
        self.name = name
        self.price = price

class CartItem:
    def __init__(self, product, qty, member=None):
        self.product = product
        self.qty = qty
        self.member = member

    def subtotal(self):
        return self.product.price * self.qty * (self.member.discount_rate if self.member else 1)

class ShoppingCart:
    def __init__(self):
        self.items = []

    def add(self, product, qty=1, member=None):
        self.items.append(CartItem(product, qty, member))

    def total(self):
        return sum(item.subtotal() for item in self.items)

    def apply_discount(self):
        return self.total()

    def show(self):
        print("-" * 30)
        for item in self.items:
            discount_info = f"会员等级：{item.member.level}, 折扣率：{item.member.discount_rate}" if item.member else "非会员"
            print(f"{item.product.name} ×{item.qty}\t￥{item.subtotal():.2f} ({discount_info})")
        print("-" * 30)
        print(f"应付总额：￥{self.apply_discount():.2f}")

# --- 测试 ---
apple = Product("苹果", 3.5)
bread = Product("面包", 4.0)
vip_member = Member('VIP')
gold_member = Member('Gold')

cart = ShoppingCart()
cart.add(apple, 4, vip_member)
cart.add(bread, 2, gold_member)
cart.show()

